package com.niguang.work.show.yxyfFace.service;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.niguang.work.show.common.util.HttpClientUtil;
import com.niguang.work.show.common.util.XmlUtils;
import com.niguang.work.show.yxyfFace.vo.SynMemberResultVo;
import com.niguang.work.show.yxyfFace.vo.SynchroMembersVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class YmyfFaceImpl implements YmyfFaceService {

    /**
     * 链接  TelpoFace平台 地址
     */
    private static final String SYN_MEMBER_URL = "http://123.207.254.37/WCUCenterCord/service/i_gongde_757_service/i_gongde_757_service_v01_34_235.aspx";


    @Override
    public SynMemberResultVo synMembers(SynchroMembersVo synchroMembersVo) {
        String postXml = HttpClientUtil.postXml(SYN_MEMBER_URL, synchroMembersVo);
        log.info("开始同步新版人员信息：{}", synchroMembersVo);
        SynMemberResultVo synMemberResultVo = XmlUtils.xmlToBean(SynMemberResultVo.class, postXml);
        log.info("同步员工返回信息：{}", synMemberResultVo);
        return synMemberResultVo;
    }

    @Override
    public Integer batchSynMembers(List<SynchroMembersVo> list) {
        int num = 0;
        if (CollectionUtils.isNotEmpty(list)) {
            for (SynchroMembersVo p : list) {
                SynMemberResultVo synMemberResultVo = synMembers(p);
                num = synMemberResultVo.getSync_success() == 0 ? num + 1 : num;
            }
            log.info("批量同步会员信息总：{}条,同步成功：{}条，同步失败：{}条", list.size(), num, list.size() - num);
        } else {
            log.info("批量同步会员未传入用户信息，同步条数：0条");
        }
        return num;
    }


}
